<!-- 模板列表的内容 -->
<template>
  <evaluation-template :records="records">
    <template #default="{ item }">
      <t-dropdown
        placement="right-top"
        trigger="click"
        :options="currentDropdownOptions(item)"
        @click="clickHandle($event, item.id)"
      >
        <div class="tdesign-demo-dropdown-trigger">
          <t-button variant="text" shape="square">
            <ellipsis-icon size="24" />
          </t-button>
        </div>
      </t-dropdown>
      <t-tag
        v-if="item.status === TEMPLATE_STATUS.RELEASED"
        theme="success"
        style="transform: scale(0.8); position: relative; top: 4px; right: 8px"
        >已发布</t-tag
      >
    </template>
  </evaluation-template>
</template>

<script>
import { mapState,mapGetters } from 'vuex';
import EvaluationTemplate from '@/components/EvaluationTemplate/index.vue';
import {
  DROPDOWN_STATUS,
  TEMPLATE_STATUS,
  dropdownOptions,
  otherDropdownOptions,
} from '@/constants/risk-assessment-template';
import { EllipsisIcon } from 'tdesign-icons-vue';

export default {
  name: 'RAT-Content',
  components: { EvaluationTemplate, EllipsisIcon },
  props: {
    records: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      TEMPLATE_STATUS,
      dropdownOptions,
      otherDropdownOptions,
    };
  },
  computed: {
    ...mapState('user', ['userInfo']),
    ...mapGetters({
      orgId: 'user/orgId',
    }),
  },
  methods: {
    currentDropdownOptions(item) {
      if (this.userInfo.roleId !== 1 && this.orgId !== item.orgId) return otherDropdownOptions;
      const options = JSON.parse(JSON.stringify(dropdownOptions));
      if (item.status === TEMPLATE_STATUS.SAVED) {
        options.unshift({ content: '发布模板', value: DROPDOWN_STATUS.RELEASE });
      }
      return options;
    },
    clickHandle(e, id) {
      if (e.value === DROPDOWN_STATUS.EDIT) {
        this.$router.push({ path: '/risk-assessment/template/create', query: { id } });
      } else if (e.value === DROPDOWN_STATUS.RELEASE) {
        this.$emit('releaseHandle', id);
      } else if (e.value === DROPDOWN_STATUS.COPY) {
        this.$emit('copyHandle', id);
      } else if (e.value === DROPDOWN_STATUS.DELETE) {
        this.$emit('deleteHandle', id);
      }
    },
  },
};
</script>
